/**************using hash map found the index of elements which sum is target in the array*************/

#include <iostream>
#include <stdlib.h>
#include <vector>
#include <map>

using namespace std;

class Solution{
public:
    vector<int>twosum(vector<int>&nums,int target)
    {
        vector<int> ans;
        map<int,int> hashmap;
        for(int i=0;i<nums.size();i++)
        {
            if(hashmap[target-nums[i]]&&hashmap[target-nums[i]]!=i+1)
            {
                ans.push_back(i);
                ans.push_back(hashmap[target-nums[i]]-1);
                return ans;
            }
            hashmap[nums[i]]=i+1;
        }
        return ans;
    }
};

    int main ()
    {
        vector<int> nums,ans;
        int a[]={2,9,7,11};
        int target=11;
        for(int i=0;i<4;i++)
            nums.push_back(a[i]);
        Solution aa;

        ans=aa.twosum(nums,target);
        cout<<ans[0]<<endl<<ans[1]<<endl;

        system("pause");
        return 0;
    }